package com.lsl.test1;

import cn.hutool.core.convert.Convert;

import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Date;

/**
 * @author lishuailong
 * @create 2020-07-07 14:28
 */
public class TestG {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s1 = "hello123";
        final  String s2 = "hello";
        String s3 = "123";
        String s4 = "hello"+"123";
        String s5 = s2+"123";

        System.out.println(s1==s4);//true
        System.out.println(s1==s5);//false

        // 字符串编码 解码

        String sz = "我爱你中国！";

        //编码
        byte[] bytes = sz.getBytes();
        System.out.println(Convert.toStr(bytes));

        // 解码
        System.out.println(new String(bytes));

        // 设置编码
        //编码
        byte[] bytes1 = sz.getBytes("gbk");
        System.out.println(Convert.toStr(bytes1));

        // 解码
        System.out.println(new String(bytes1,"gbk"));

        System.out.println("************************************");
        //1.实例化
        //方式一：创建其子类（GregorianCalendar的对象
        //方式二：调用其静态方法getInstance()
        Calendar calendar = Calendar.getInstance();
//        System.out.println(calendar.getClass());

        //2.常用方法
        //get()
        int days = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(days);
        System.out.println(calendar.get(Calendar.DAY_OF_YEAR));

        //set()
        //calendar可变性
        calendar.set(Calendar.DAY_OF_MONTH,22);
        days = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(days);

        //add()
        calendar.add(Calendar.DAY_OF_MONTH,-3);
        days = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(days);

        //getTime():日历类---> Date
        Date date = calendar.getTime();
        System.out.println(date);

        //setTime():Date ---> 日历类
        Date date1 = new Date();
        calendar.setTime(date1);
        days = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println(days);
    }
}
